#include "hal_position.h"
#include "string.h"

static MotorInformSt MotorInform                       = {0};
static uint8_t motor_num_pick[MOTOR_MAX_ERROR_CHANNEL] = {0};

// 电机信息设置
void hal_PositionWrite(uint8_t groupid, uint8_t motor_num, uint32_t position) { MotorInform.Position[groupid - 1][motor_num - 1] = position; }

void hal_StepStateWrite(uint8_t groupid, uint8_t motor_num, uint32_t stepstate) { MotorInform.StepState[groupid - 1][motor_num - 1] = stepstate; }

void hal_DirectionWeite(uint8_t groupid, uint8_t motor_num, uint32_t direction) { MotorInform.Direction[groupid - 1][motor_num - 1] = direction; };

void hal_StepNumberWrite(uint8_t groupid, uint8_t motor_num, uint32_t stepnumber) { MotorInform.StepNumber[groupid - 1][motor_num - 1] = stepnumber; }

// 电机信息获取
uint32_t hal_PositionRead(uint8_t groupid, uint8_t motor_num) { return MotorInform.Position[groupid - 1][motor_num - 1]; }

uint32_t hal_StepStateRead(uint8_t groupid, uint8_t motor_num) { return MotorInform.StepState[groupid - 1][motor_num - 1]; }

uint32_t hal_DirectionRead(uint8_t groupid, uint8_t motor_num) { return MotorInform.Direction[groupid - 1][motor_num - 1]; }

uint32_t hal_StepNumberRead(uint8_t groupid, uint8_t motor_num) { return (motor_num == 0)?  0: MotorInform.StepNumber[groupid - 1][motor_num - 1]; }

// 可用电机设置
void hal_MotorNumWrite(uint8_t groupid, uint8_t motor_num) { motor_num_pick[groupid - 1] = motor_num; }

uint8_t hal_MotorNumRead(uint8_t groupid) { return motor_num_pick[groupid - 1]; }

void hal_MotorNumReset() { memset(motor_num_pick, 0, sizeof(motor_num_pick)); }
